// Copyright [2020] <Weaverzhu>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

const int N = 305;


int n, m, k;
int a[N][N];
int rb[N][N];

int p2[10], Log[N];
struct ST {
    static const int SP = 10;
    int dat[SP][N];
    void init() {
        p2[0] = 1;
        for (int i=1; i<SP; ++i)
            p2[i] = p2[i-1] << 1;
        Log[1] = 0;
        for (int i=2; i<N; ++i)
            Log[i] = Log[i >> 1] + 1;
    }
    void init(int a[], int n)
    {
        for (int i=1; i<=n; ++i)
            dat[0][i] = a[i];
        for (int i=1; i<SP; ++i)
            for (int j=1; j<=n; ++j)
                dat[i][j] = min(dat[i-1][j], dat[i-1][j + p2[i-1]]);
    }
    int q(int l, int r) {
        int Lg = Log[r-l+1];
        return min(dat[Lg][l], dat[Lg][r-p2[Lg]+1]);
    }
} ds[N];

int main(int argc, char const *argv[]) {
    int t;
    ds[0].init();
    scanf("%d", &t);
    for (int kk=0; kk<t; ++kk) {
        scanf("%d%d%d", &n, &m, &k);
        for (int i=1; i<=n; ++i)
            for (int j=1; j<=m; ++j)
                scanf("%d", &a[i][j]);
        for (int i=1; i<=n; ++i) {
            for (int j=1; j<=m; ++j) {
                int mx = a[i][j], mi = a[i][j];
                rb[i][j] = j;
                for (int kk=j+1; kk<=m; ++kk) {
                    mx = max(mx, a[i][kk]);
                    mi = min(mi, a[i][kk]);
                    // dbg(i, j, kk, mx, mi);
                    if (mx - mi <= k)
                        rb[i][j] = kk;
                    else
                        break;
                }
                // dbg(i, j, rb[i][j]);
            }
        }

        for (int i=1; i<=m; ++i) {
            static int t[N];
            for (int j=1; j<=n; ++j)
                t[j] = rb[j][i];
            ds[i].init(t, n);
        }
        int ans = 0;
        for (int i=1; i<=n; ++i)
            for (int j=i; j<=n; ++j)
                for (int st=1; st<=m; ++st)
                {
                    int x = j-i+1, y = ds[st].q(i, j) - st + 1;
                    // dbg(x, y, ans);
                    ans = max(ans, x * y);
                }
        // for (int i=1; i<=n; ++i)
        //     for (int j=1; j<=m; ++j)
        //         dbg(i, j, rb[i][j]);
        printf("Case #%d: %d\n", kk+1, ans);
    }
    return 0;
}
